package cn.eud.hunau.common;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hb
 * @date 2025-06-18 16:05:58
 */
public class R   {
    //标识响应的结果是否成功
    private Boolean success;
    //携带响应信息
    private String message;

    //响应的业务相关的状态码（项目中自定义）
    private Integer code;

    //响应的结果
    private Map<String,Object> data;

    private R(){

    }

    public static R ok(){
        R r=new R();
        r.setSuccess(ResultCodeEnum.SUCCESS.getSuccess());
        r.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        r.setCode(ResultCodeEnum.SUCCESS.getCode());
        return r;
    }

    public static R error(){
        R r=new R();
        r.setSuccess(ResultCodeEnum.ERROR.getSuccess());
        r.setMessage(ResultCodeEnum.ERROR.getMessage());
        r.setCode(ResultCodeEnum.ERROR.getCode());
        return r;
    }

    public static R setResult(ResultCodeEnum codeEnum){
        R r=new R();
        r.setSuccess(codeEnum.getSuccess());
        r.setCode(codeEnum.getCode());
        r.setMessage(codeEnum.getMessage());
        return r;
    }


    public R data(Map<String ,Object> data){
        this.setData(data);
        return this;
    }

    public R data(String key,Object value){
        if(this.data ==null){
            this.data=new HashMap<>();
        }

        this.data.put(key,value);
        return this;
    }


    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }

    public R success(Boolean success){
        this.setSuccess(success);
        return this;
    }


    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }

    public Map<String, Object> getData() {
        return data;
    }
}